package com.qf.commons.event.mq.rabbitmq.listener;

import com.qf.commons.event.core.standrad.ConsumerStandrad;
import com.qf.commons.event.entity.QphoneMessage;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.utils.SerializationUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 消息的监听器
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
public class MsgListener {

    @Autowired
    private ConsumerStandrad consumerStandrad;

    @RabbitListener(queues = "event-${spring.application.name}")
    public void msgListener(Message message){
        //拆解其中的数据
        byte[] msg = message.getBody();
        //反序列化
        QphoneMessage qphoneMessage = (QphoneMessage) SerializationUtils.deserialize(msg);
        //调用上层接口，进行消息的处理
        consumerStandrad.msgHandler(qphoneMessage);
    }
}
